package edu.washington.ling.syntric.io;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;

import edu.washington.ling.syntric.util.LaTeXUtils;


public class ExampleDocWriterLaTeX extends ExampleDocWriter {

	private PrintStream pStream;
	
	public ExampleDocWriterLaTeX(String path) throws IOException {
		super(path);
		try {
			pStream = new PrintStream(new FileOutputStream(new File(path)), true, "UTF8");
		} 
		catch(UnsupportedEncodingException e) {
			pStream = new PrintStream(new FileOutputStream(new File(path)), true);
		}
		pStream.print(LaTeXUtils.formatPreamble("Tree Output"));
		pStream.println("\\begin{enumerate}");
	}
	@Override
	public void close() {
		pStream.println("\\end{enumerate}");
		pStream.println("\\end{document}");
		pStream.close();
	}
	@Override
	public void writeExample(Example exr) {
		writeExample(exr, super.allLayers);
	}
	@Override
	public void writeExample(Example exr, String[] includeLayers) {
		if (exr.hasSystemTreeReps()) {
			LaTeXUtils.writeExampleRep(exr, includeLayers, pStream);
		} else {
			pStream.print("\\vbox{");
			LaTeXUtils.writeExampleRep(exr, includeLayers, pStream);
			pStream.print("}");
		}
	}

}
